#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "unitTest2.h"


int unitTest2() {
    
    int seed = 1000;
    int numPlayer = 2;
    
	struct gameState G;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
		   sea_hag, tribute, smithy};
	
	
	printf("=========================\n TESTING BUYCARD() FUNCTION \n=========================\n");
	
	initializeGame(numPlayer, k, seed, &G);
	
	
	
	//test that gard was gained, coins went down, and number of buys went down.
				
	G.numBuys = 0;
	if(buyCard(1, &G)==-1){
		printf("TEST PASSED: Not allowed to buy when numBuys is 0\n");
	} else {
		printf("TEST FAILED: Should have returned -1, Not allowed to buy when numBuys is 0\n");
	}
	
	//Set supply count for card trying to buy to 0.
	G.numBuys = 1;
	G.supplyCount[1] = 0;
	if(buyCard(1, &G)==-1){
		printf("TEST PASSED: Not allowed to buy when there are no cards left\n");
	} else {
		printf("TEST FAILED: Should have returned -1, Not allowed to buy when there are no cards left\n");
	}
	
	//Set supply count for card trying to buy to 0.
	G.supplyCount[1] = 1;
	G.coins = 0;
	if(buyCard(1, &G)==-1){
		printf("TEST PASSED: Not allowed to buy when don't have enough coins\n");
	} else {
		printf("TEST FAILED: Should have returned -1, Not allowed to buy when don't have enough coins\n");
	}
	
	G.coins = 2;
	buyCard(1, &G);
	if(G.phase == 1){
		printf("TEST PASSED: Phase set to 1\n");
	} else {
		printf("TEST FAILED: Phase != 1\n");
	}
	
	if(G.coins == 0){
		printf("TEST PASSED: 2 coins removed\n");
	} else {
		printf("TEST FAILED: 2 coins should have been removed\n");
	}
	
	if(G.numBuys == 0){
		printf("TEST PASSED: one buy removed\n");
	} else {
		printf("TEST FAILED: one buy should have been removed\n");
	}

    return 0;
}


